// $codepro.audit.disable
/*
 * UserTest.java
 */
package edu.gatech.oad.user;

import static org.junit.Assert.*;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Date;

import org.junit.Test;

import edu.gatech.oad.persistence.PersistenceManager;


public class UserTest {

	@Test
	public void testAccountsController() {
		AccountsController controller = AccountsController.sharedController();
		assertFalse(controller == null);
		assertEquals(0, controller.getUsers().size());
		
		Patient p = controller.addPatientForUsername("patient");
		Patient p2 = controller.addPatientForUsername("patient");
		Doctor d = controller.addDoctorForUsername("patient");
		
		assertNotNull(p);
		assertNull(p2);
		assertNull(d);
		
		d = controller.getDoctorForUsername("patient");
		
		assertNull(d);
		
		p2 = controller.getPatientForUsername("patient");
		
		assertTrue(p.compareTo(p2) == 0);
		assertEquals(p, p2);
		
		System.out.println(p.toString());
		
		String tmpDir = System.getProperty("java.io.tmpdir");
		String filename = new File(tmpDir, "testing.dat").toString();
		
		try {
			controller.save(filename);
			AccountsController test = (AccountsController) PersistenceManager.load(filename);
			
			assertEquals(controller.getUsers().size(), test.getUsers().size());
			assertEquals(controller.getPatients().size(), test.getPatients().size());
			assertEquals(controller.getDoctors().size(), test.getDoctors().size());
			assertEquals(controller.getNurses().size(), test.getNurses().size());
			assertEquals(controller.getReceptionists().size(), test.getReceptionists().size());
			assertEquals(controller.getSystemAdministrators().size(), test.getSystemAdministrators().size());
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			assertFalse(true);
		}
	}
	
	@Test
	public void testUserController() {
		UserController c1 = new UserController(Nurse.class, "nurse");
		
		System.out.println(c1.getUser().toString());
		
		c1.setUserFirstName("Carla");
		c1.setUserLastName("Turk");
		c1.setUserEmailAddress("carla.turk@sacredheart.org");
		c1.setUserBirthday(new Date());
		c1.setUserGender("Woman");
		c1.setUserPhoneNumber("555-5555");
		
		System.out.println(c1.getUser().toString());
	}
	
}
